package com.plugin.sproutcore.lang;

import java.util.ArrayList;
import java.util.List;

public class WindowsExecutionEnvironment implements IExecutionEnvironment
{
	private IShell shell;
	
	public List<String> generateCommandLine(List<String> command) 
	{
		command = new ArrayList<String>(command);
		if (command.get(0).equals("kill"))
		{
			// kill a process on windows
			command.set(0,"taskkill");
			command.add(1,"/F");
			command.add(2,"/PID");
		}
		return command;
	}

	public IShell generateShell() 
	{
		if (shell == null) {
			shell = new WindowsShell();
		}
		return shell;
	}

	private static class WindowsShell implements IShell {

		private static List<String> shellCommand = null;
		
		public List<String> getShellCommand() 
		{
			if (shellCommand == null) 
			{
				final String osName = System.getProperty("os.name" );
				if ( osName.equalsIgnoreCase( "Windows 95" ) ) 
				{
					shellCommand = new ArrayList<String>();
					shellCommand.add("command.com");
					shellCommand.add("/C");
				}
				else
				{
					shellCommand = new ArrayList<String>();
					shellCommand.add("cmd.exe");
					shellCommand.add("/C");
				}
			}
			return shellCommand;
		}

	}
	
}
